using Manso.cBot.Common;

namespace Manso.cBot.DefaultModules.Kos
{
    public class KosGetCommand : ICommand
    {
        private readonly ListenToEnum _listenTo;
        private readonly string _command;
        private readonly string _help;
        private readonly string _usage;
        private readonly AccessControlLevel _accessLevel;

        public KosGetCommand()
        {
            _listenTo = ListenToEnum.Both;
            _command = "KosGet";
            _help = "Show you if a target is on KOS list";
            _usage = "kosget character_name";
            _accessLevel = AccessControlLevel.Basic;
        }

        public ListenToEnum ListenTo
        {
            get { return _listenTo; }
        }

        public string Command
        {
            get { return _command; }
        }

        public string Help
        {
            get { return _help; }
        }

        public string Usage
        {
            get { return _usage; }
        }

        public AccessControlLevel AccessLevel
        {
            get { return _accessLevel; }
        }

        public void ExecuteCommand(string[] args, string executedBy, ListenToEnum listenTo)
        {
            if (args.Length == 0 || args[0].Length == 0)
            {
                cBotContext.Instance.SendMessage("Error in arguments. Try help for usage information", executedBy, listenTo);
            }

            KosList kosList = new KosList();
            kosList.ReadXml("Kos/KosList.xml");

            foreach (KosList.KosTargetRow kosTargetRow in kosList.KosTarget)
            {
                if (kosTargetRow.CharacterName.ToLower().Equals(args[0].ToLower()))
                {
                    cBotContext.Instance.SendMessage(string.Format("Yes, it is on list. Kill! Kill! (Target added {0} time(s) to list)", kosTargetRow.GetAddedByRows().Length), executedBy,
                                                     listenTo);
                    return;
                }
            }

            cBotContext.Instance.SendMessage("Player not found on KOS list", executedBy, listenTo);
        }
    }
}